package com.volunteer.util;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * 密码生成器 - 用于生成 BCrypt 加密密码
 */
public class PasswordGenerator {
    public static void main(String[] args) {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        String password = "123456";
        
        // 生成多个密码哈希用于验证
        System.out.println("为密码 '" + password + "' 生成的 BCrypt 哈希：");
        System.out.println("=".repeat(80));
        
        for (int i = 1; i <= 3; i++) {
            String hash = encoder.encode(password);
            boolean matches = encoder.matches(password, hash);
            System.out.println("\n哈希 " + i + ":");
            System.out.println(hash);
            System.out.println("验证结果: " + (matches ? "✓ 正确" : "✗ 错误"));
        }
        
        System.out.println("\n" + "=".repeat(80));
        System.out.println("\n请在数据库中使用以上任意一个哈希值更新用户密码。");
        System.out.println("\nSQL 更新语句示例：");
        String newHash = encoder.encode(password);
        System.out.println("UPDATE sys_user SET password = '" + newHash + "' WHERE username = 'admin';");
    }
}

